🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / connections / src / commonMain / kotlin / org / meshtastic / feature / connections / ui / LocalNetworkGateAction.kt
Displaying Raw • Download
feature/connections/src/commonMain/kotlin/org/meshtastic/feature/connections/ui/LocalNetworkGateAction.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 4.15 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.connections.ui
Tff7b72import T7ee787org.meshtastic.core.ui.util.PermissionStatus
T8b949e/**
* What the Connections UI should do when the user takes a TCP-connect action that may need `ACCESS_LOCAL_NETWORK`.
*
* The policy is prompt-when-possible, warn-when-not, and NEVER block: on Android 17 (API 37) the permission gates the
* socket itself — an ungranted local connect times out rather than failing fast — but a TCP address says nothing about
* locality. A radio reached over a public IP, a port-forward, or a VPN needs no local-network permission at all, so a
* hard block on the permission would break connections that were never subject to it.
*/
Tff7b72enum Tff7b72class T56d364LocalNetworkGateAction Tb4b4b4{
T8b949e/** The permission is held; run the connect. */
Te6edf3PROCEEDTb4b4b4,
T8b949e/** The system will still show a prompt; request in-context and run the connect once the request resolves. */
Te6edf3REQUEST_PERMISSIONTb4b4b4,
T8b949e/**
* The system will no longer prompt. Surface the warning that names the fix (system settings), then run the connect
* anyway — the target may not be local, and the OS enforces the permission at the socket regardless.
*/
Te6edf3PROCEED_WITH_WARNINGTb4b4b4,
Tb4b4b4}
T8b949e/**
* Pure classifier for gating a TCP-connect action on `ACCESS_LOCAL_NETWORK`. Kept side-effect-free and
* platform-agnostic so it can be unit-tested in `commonTest` without an Android `Activity`.
*
* Inert everywhere else: `rememberLocalNetworkPermissionState()` reports [PermissionStatus.GRANTED] below API 37 and on
* desktop/iOS, so this always returns [LocalNetworkGateAction.PROCEED] there.
*/
Tff7b72fun Td2a8fflocalNetworkGateActionTb4b4b4(Te6edf3statusTb4b4b4: Te6edf3PermissionStatusTb4b4b4)Tb4b4b4: Te6edf3LocalNetworkGateAction Tff7b72= Tff7b72when Tb4b4b4(Te6edf3statusTb4b4b4) Tb4b4b4{
Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTED Tff7b72-Tff7b72> Te6edf3LocalNetworkGateActionTb4b4b4.Te6edf3PROCEED
Te6edf3PermissionStatusTb4b4b4.Te6edf3PERMANENTLY_DENIED Tff7b72-Tff7b72> Te6edf3LocalNetworkGateActionTb4b4b4.Te6edf3PROCEED_WITH_WARNING
Te6edf3PermissionStatusTb4b4b4.Te6edf3NOT_REQUESTED Tff7b72-Tff7b72> Te6edf3LocalNetworkGateActionTb4b4b4.Te6edf3REQUEST_PERMISSION
Te6edf3PermissionStatusTb4b4b4.Te6edf3DENIED_CAN_RETRY Tff7b72-Tff7b72> Te6edf3LocalNetworkGateActionTb4b4b4.Te6edf3REQUEST_PERMISSION
Tb4b4b4}
T8b949e/** How a connect stashed behind an in-flight permission request should be resolved once the status moves. */
Tff7b72enum Tff7b72class T56d364PendingTcpConnectResolution Tb4b4b4{
T8b949e/** The grant landed; run the stashed connect. */
Te6edf3CONNECTTb4b4b4,
T8b949e/** The request resolved as a denial; warn, then run the stashed connect anyway (see the policy above). */
Te6edf3CONNECT_WITH_WARNINGTb4b4b4,
T8b949e/** The status has not moved since the stash; the request is still unresolved. */
Te6edf3KEEP_WAITINGTb4b4b4,
Tb4b4b4}
T8b949e/**
* Resolves a TCP connect stashed while a permission request was in flight, given the status at stash time and now.
*
* A status *transition* is the only observable signal that the request resolved: the result callback recomputes the
* status, but a same-value recomputation is invisible to composition. Denials do transition on modern Android
* (NOT_REQUESTED → DENIED_CAN_RETRY, and a second denial → PERMANENTLY_DENIED), so the practical dangling case is
* limited to OEM flows that re-answer with an identical status — where the stash simply waits to be overwritten by the
* next tap.
*/
Tff7b72fun Td2a8ffresolvePendingTcpConnectTb4b4b4(
Te6edf3stashedStatusTb4b4b4: Te6edf3PermissionStatusTb4b4b4,
Te6edf3currentStatusTb4b4b4: Te6edf3PermissionStatusTb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3PendingTcpConnectResolution Tff7b72= Tff7b72when Tb4b4b4{
Te6edf3currentStatus Tff7b72=Tff7b72= Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTED Tff7b72-Tff7b72> Te6edf3PendingTcpConnectResolutionTb4b4b4.Te6edf3CONNECT
Te6edf3currentStatus Tff7b72!Tff7b72= Te6edf3stashedStatus Tff7b72-Tff7b72> Te6edf3PendingTcpConnectResolutionTb4b4b4.Te6edf3CONNECT_WITH_WARNING
Tff7b72else Tff7b72-Tff7b72> Te6edf3PendingTcpConnectResolutionTb4b4b4.Te6edf3KEEP_WAITING
Tb4b4b4}
Served by rngit 1.5.2 - Generated in 0.14s